package P912;

import org.junit.Test;

/**
 * @Author DJ同学
 * @Date 2021/2/28 8:21
 * @Version 1.0
 * @Name 排序数组
 * @Problem https://leetcode-cn.com/problems/sort-an-array/
 * 冒泡排序
 *
 */
public class Solution {
    @Test
    public void test(){
        for (int i : sortArray(new int[]{5, 2, 3, 1})) {
            System.out.println(i);
        }
        return;
    }
    public int[] sortArray(int[] nums) {
        int temp;
        //一轮一轮的进行不断地交换
        for(int i = 0;i<nums.length-1;i++){
            for(int j=i+1;j<nums.length;j++){
                if(nums[i]>nums[j]){
                    temp = nums[i];
                    nums[i] = nums[j];
                    nums[j] = temp;
                }
            }
        }
        return nums;
    }
}
